<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link rel="shortcut icon" th:href="@{/img/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/img/favicon.ico}" type="image/x-icon"/>
    <link th:href="@{/css/style.css}" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" th:src="@{/js/jquery.js}"></script>
    <script type="text/javascript" th:src="@{/laydate/laydate.js}"></script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li><a th:href="@{/sys/users/userall}">系统管理</a></li>
        <li><a th:href="@{/sys/dept/deptList}">部门管理</a></li>
        <li><a href="#">添加</a></li>
    </ul>
</div>
<div class="formbody">
    <form th:action="@{/sys/dept/addDept}" method="post">
    <div class="formtitle"><span>部门信息</span></div>
    <ul class="forminfo">
        <li>
            <label>部门名称</label>
            <input name="deptName" type="text" class="dfinput"/>
            <i>必填，不能超过30个字符</i>
        </li>


        <li>
            <label>所属区域</label>
            <select class="dfselect" name="pId" onchange="getCity(this.value)">
                <option value="0">请选择省份</option>
                <option th:each="p:${session.provinces}" th:text="${p.pName}" th:value="${p.id}"></option>
            </select>
            省
            <select class="dfselect" name="cId">
                <option value="0">请选择城市</option>
            </select>
            市
            <i>必选</i>
        </li>
        <input type="hidden" name="deptState" value="1"/>

        <li>
            <label>&nbsp;</label>
            <input name="" type="submit" class="btn" value="确认保存"/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="" type="button" class="btn" value="返回" onclick="window.history.go(-1);"/>
        </li>
    </ul>
    </form>
</div>
<script>

    function getCity(num) {
        // alert(num);
        //异步请求
        $.get("/erp1/ajaxCity",{"pid":num},function (data) {
            // JSON.parse(data);  data--->object
            //清空内容
            // console.log(data);
            $("select[name=cId]").html("");
            var options="<option value=''>请选择城市</option>";
            $.each(data,function (i,e) {
                options+="<option value='"+e.id+"'>"+e.cname+"</option>";
            });
            $("select[name=cId]").append(options);
        },"json");
    }
</script>
</body>
</html>
